package com.yykj.drup.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.yykj.drup.server.mapper.DeliveryAddressDao;
import com.yykj.drup.server.model.DeliveryAddress;
import com.yykj.drup.server.service.DeliveryAddressService;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zengg
 * @since 2022-03-21
 */
@Service
public class DeliveryAddressServiceImp extends ServiceImpl<DeliveryAddressDao, DeliveryAddress> implements DeliveryAddressService {

    @Override
    public void setDeliveryAddressDefault(Integer id) {
        DeliveryAddress address = this.getById(id);
        if (address == null){
            throw new RuntimeException();
        }
        UpdateWrapper<DeliveryAddress> wrapper = new UpdateWrapper();
        wrapper.eq("sns_user_id",address.getSnsUserId()).set("is_default",0);
        boolean b = this.update(wrapper);
        if (b){
            address.setIsDefault(1);
            this.updateById(address);
        }
    }
}
